﻿using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using VsxTools.Attributes;
using VsxTools.UtilityTypes;

namespace VsxTools.ToolWindow
{
    public class VsxToolWindowForm<TPackage, TControl> : ToolWindowPane where TPackage : Package
        where TControl : Form, new()
    {
        private readonly TControl _control;

        protected VsxToolWindowForm():base(null)
        {
            foreach (var attribute in GetType().GetCustomAttributes(false))
            {
                var captionAttribute = attribute as InitialCaptionAttribute;
                if (captionAttribute != null)
                {
                    Caption = StringResolver<TPackage>.Resolve(captionAttribute.Value);
                    continue;
                }
                var resIdAttribute = attribute as BitmapResourceIdAttribute;
                if (resIdAttribute != null)
                {
                    BitmapResourceID = resIdAttribute.ResourceId;
                    BitmapIndex = resIdAttribute.BitmapIndex;
                }
            }

            _control = new TControl();
        }

        public TControl Control
        {
            get { return _control; }
        }

        public override IWin32Window Window
        {
            get { return _control; }
        }
    }
}
